import store from "@/pages/maneuver/store";
import axios from '@/http-config/http'; // 引入http配置

export const dateFormatter = (value) => {
    let date = new Date(value);
    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    m = m < 10 ? '0' + m : m;
    let d = date.getDate();
    d = d < 10 ? '0' + d : d;
    let h = date.getHours();
    h = h < 10 ? '0' + h : h;
    let minute = date.getMinutes();
    minute = minute < 10 ? '0' + minute : minute;
    let second = date.getSeconds();
    second = second < 10 ? '0' + second : second;
    return y + '/' + m + '/' + d + ' ' + h + ':' + minute + ':' + second;
}

export const getUser = (id) => {
    const findRes = store.getters.userList.find(el => el.id == id)
    return findRes || {}
}

export const getOrg = (id) => {
    const findRes = store.getters.orgList.find(el => el.id == id)
    return findRes || {}
}

export const downLoadFile = (item) => {
    axios['maneuver-scenario'].getFile('/fileManage/downloadFile?id=' + item.id).then(res => {
        var blob = new Blob([res])
        if (window.navigator.msSaveOrOpenBlob) {
          // IE
          navigator.msSaveBlob(blob, item.fileName)
        } else {
          const ele = document.createElement('a')
          ele.setAttribute('href', URL.createObjectURL(blob)) //设置下载文件的url地址
          ele.setAttribute('download', item.fileName)
          ele.click()
          document.body.removeChild(ele)
          URL.revokeObjectURL(ele.href)
        }
    })
}